package ar.com.ford.it.fullEconomics.view.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import ar.com.ford.it.fullEconomics.view.form.FTPContentForm;
import com.ford.it.ftp.FtpProxyClient;



public class InterfaceFTPGetAction extends Action {

	 public ActionForward execute(ActionMapping mapping, ActionForm form,
	            HttpServletRequest request, HttpServletResponse response)
	             
	 {
	    try {
           String host = "sye1.dearborn.ford.com";
           String user = "BZBFTPH";
           String pass = "ftp33wi";

           FtpProxyClient ftp = new FtpProxyClient(host,user,pass);
	
		   ftp.setAsciiMode();
		   //ftp.changeDirectory("/tmp/dropzone");

		   //BufferedInputStream os = new BufferedInputStream()
//		   FileOutputStream os = new FileOutputStream("c:\\temp\\x.txt");
		   
		   //String arch = ftp.getFile("'sex.pdr.runchee'").toString(); // getFile(os, "'sex.pdr.runchee'");
		   String arch = ftp.getCurrentDirectory();
		   FTPContentForm formulario = (FTPContentForm) form;
		   formulario.setContenidoArchivo(arch);
           
           /*PrintWriter out = response.getWriter();
           out.println("<html><head></head><body>");
           out.println("<h1>Ford Argentina S&#46;C&#46;A&#46;</h1>");
           out.println("<h2>Archivo recibido</h2>");
           out.println("<p>+os.toString()+</p>");
		   out.println("</body></html>");
           out.flush();
           return out;
           */
           //os.close();

           //FileInputStream =is = new FileInputStream("c:\\temp\\y.txt");
           //ftp.putFile(is, "y.txt");
           //is.close();

		   ftp.cleanup();
		   
		   return mapping.findForward("success");
		
        } catch (Exception e) {
        	System.out.println("No se pudo establecer conexion con FTP server " + e.getMessage());
        	return null;
        }
        
	 }
	 
	 
}
